﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace City
{
	public class City
	{
		List<Building> Buildings=new List<Building>();

		public int width, height;

		public CityTile[,] Field;

		public DijkstraGraph<CityTile> Roads;

		public City(int iwidth, int iheight)
		{
			width = iwidth;
			height = iheight;
			Field = new CityTile[width, height];
			for (int i = 0; i < width; i++)
				for (int j = 0; j < height; j++)
					Field[i, j] = new CityTile(i, j);
			Roads = new DijkstraGraph<CityTile>();
		}

		#region Roads
		public void AddRoad(int X, int Y)
		{
			var T = Roads.AddPoint(Field[X, Y]);
			foreach (var t in Roads.Points)
			{
				if (Math.Abs(t.Content.x - X) + Math.Abs(t.Content.y - Y) == 1)
					Roads.Bind(T, t, 1);
			}
			Console.WriteLine(Roads.Edges.Count);
		}
		public void DelRoad(int X, int Y)
		{
			//Roads.Delete();
		}
		#endregion
		public void Process(double dt)
		{

		}

		public void Display()
		{
			foreach (var T in Field)
			{
				Console.SetCursorPosition(T.x, T.y);
				switch (T.type)
				{
					case TileType.None:
						Console.Write("?");
						break;
					case TileType.Water:
						Console.BackgroundColor = ConsoleColor.Blue;
						Console.Write(" ");
						break;
					case TileType.Water_Deep:
						Console.BackgroundColor = ConsoleColor.DarkBlue;
						Console.Write(" ");
						break;
					case TileType.Grass:
						Console.BackgroundColor = ConsoleColor.DarkGreen;
						Console.Write(" ");
						break;
					case TileType.Grass2:
						Console.BackgroundColor = ConsoleColor.Green;
						Console.Write(" ");
						break;
					case TileType.Grass3:
						Console.BackgroundColor = ConsoleColor.DarkYellow;
						Console.Write(" ");
						break;
					case TileType.Dirt:
						Console.BackgroundColor = ConsoleColor.Yellow;
						Console.Write(" ");
						break;
					default:
						break;
				}
				Console.ResetColor();
			}
		}
	}
	public enum TileType
	{
		None,
		Water,
		Water_Deep,
		Road,
		Grass,
		Grass2,
		Grass3,
		Dirt,
	}
	public class CityTile
	{
		public int x, y;
		public TileType type = TileType.None;
		public CityTile(int ix, int iy)
		{
			x = ix;
			y = iy;
		}
	}
}